/*
 *
 * Copyright(c) 2010 Safelayer Secure Communications
 *
 * This is open source software, placed under the terms of the
 * GNU GENERAL PUBLIC LICENSE Version 3.
 * Please see: http://www.gnu.org/licenses/gpl-3.0.txt
 * 
 * Permission to use, copy, modify, and distribute this software
 * for any purpose and without fee is hereby granted, provided
 * that the above copyright notices appear in all copies and that
 * both the copyright notice and this permission notice appear in
 * supporting documentation.
 * 
 */
package com.neuralnoise.foaf.core;

import java.math.BigDecimal;

/**
 * Models a SpatialThing. Anything with spatial extent, i.e. size, shape, or position. e.g. people,
 * places, bowling balls, as well as abstract areas like cubes.
 * <p>
 * For more info see GEO Vocabulary.
 * 
 * @author victor.martinez <swtp@safelayer.com>
 */
public class SpatialThing extends Thing implements Spatial {

	/** The WGS84 latitude of a SpatialThing (decimal degrees). */
	private BigDecimal latitude;

	/** The WGS84 longitude of a SpatialThing (decimal degrees). */
	private BigDecimal longitude;

	/** The WGS84 altitude of a SpatialThing (decimal meters above the local reference ellipsoid). */
	private BigDecimal altitude;

	public SpatialThing(String uri) {
		super(uri);
	}

	public SpatialThing() {
		super(null);
	}

	/**
	 * @see com.neuralnoise.foaf.core.Spatial#getLatitude()
	 */
	public BigDecimal getLatitude() {
		return latitude;
	}

	/**
	 * @see com.neuralnoise.foaf.core.Spatial#setLatitude(long)
	 */
	public void setLatitude(BigDecimal latitude) {
		this.latitude = latitude;
	}

	/**
	 * @see com.neuralnoise.foaf.core.Spatial#getLongitude()
	 */
	public BigDecimal getLongitude() {
		return longitude;
	}

	/**
	 * @see com.neuralnoise.foaf.core.Spatial#setLongitude(long)
	 */
	public void setLongitude(BigDecimal longitude) {
		this.longitude = longitude;
	}

	/**
	 * @see com.neuralnoise.foaf.core.Spatial#getAltitude()
	 */
	public BigDecimal getAltitude() {
		return altitude;
	}

	/**
	 * @see com.neuralnoise.foaf.core.Spatial#setAltitude(long)
	 */
	public void setAltitude(BigDecimal altitude) {
		this.altitude = altitude;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result
				+ ((altitude == null) ? 0 : altitude.hashCode());
		result = prime * result
				+ ((latitude == null) ? 0 : latitude.hashCode());
		result = prime * result
				+ ((longitude == null) ? 0 : longitude.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		SpatialThing other = (SpatialThing) obj;
		if (altitude == null) {
			if (other.altitude != null)
				return false;
		} else if (!altitude.equals(other.altitude))
			return false;
		if (latitude == null) {
			if (other.latitude != null)
				return false;
		} else if (!latitude.equals(other.latitude))
			return false;
		if (longitude == null) {
			if (other.longitude != null)
				return false;
		} else if (!longitude.equals(other.longitude))
			return false;
		return true;
	}

}
